﻿namespace GameLib.Games
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GameLib.Games.Util;

    public abstract class AbstractModMatcherHandler<T> : IModMatcherHandler<T> where T : IMod
    {
        public event EventHandler<ModMatcherHandlerEventArgs> BeforeHandleEvent;

        public event EventHandler<ModMatcherHandlerEventArgs> AfterHandleEvent;

        public virtual ModMatcherHandlerAction HandleList(IList<MatcherStruct<T>> list)
        {
            if (list.Count > 0)
            {
                ModMatcherHandlerAction result = ModMatcherHandlerAction.DoNothing;
                foreach (MatcherStruct<T> matcherStruct in list)
                {
                    Handle(matcherStruct.Matcher, matcherStruct.Match);
                }

                return result;
            }
            else
            {
                return ModMatcherHandlerAction.DoNothing;
            }
        }

        public abstract ModMatcherHandlerAction Handle(IModMatcher matcher, T mod);

        protected void OnBeforeHandleEvent(ModMatcherHandlerEventArgs eventArgs)
        {
            if (this.BeforeHandleEvent != null)
            {
                this.BeforeHandleEvent(this, eventArgs);
            }
        }

        protected void OnAfterHandleEvent(ModMatcherHandlerEventArgs eventArgs)
        {
            if (this.AfterHandleEvent != null)
            {
                this.AfterHandleEvent(this, eventArgs);
            }
        }
    }
}
